<?php include("header.php");
include("dbconfig.php");
include("geocoder.php");

$first_name =  mysql_real_escape_string($_POST["first_name"]);
$last_name =  mysql_real_escape_string($_POST["last_name"]);
$area_code = mysql_real_escape_string($_POST["phone_num1"]);
$phone_num = mysql_real_escape_string($_POST["phone_num2"]);
$phone_num2 = mysql_real_escape_string($_POST["phone_num3"]);
$street_address = mysql_real_escape_string($_POST["street_address"]);
$second_line = mysql_real_escape_string($_POST["line2"]);
$state = mysql_real_escape_string($_POST["state"]);
$city = mysql_real_escape_string($_POST["city"]);
$zipcode = mysql_real_escape_string($_POST["zipcode"]);
$email =  mysql_real_escape_string($_POST["email"]);
$post_until = $_POST["month"] + "/" + $_POST["day"] + "/" + $_POST["year"];
$post_until =  mysql_real_escape_string($post_until);
$times =  mysql_real_escape_string($_POST["times"]);
$tree_info =  mysql_real_escape_string($_POST["tree_info"]);
$add_info =  mysql_real_escape_string($_POST["add_info"]);
$equipment = "";

$address = $street_address." ".$second_line." ".$state." ".$zipcode;
$geocodeAddress = preg_replace('/\s+/', '+', $address);
$query = <<<END
	SELECT COUNT(idpickup) FROM pickups;
END;
$result = mysql_query($query, $connection);
$result = mysql_fetch_array($result);
$id = $result[0] + 1;


$geocode = geocode($geocodeAddress);
$lat = $geocode["lat"];
$lng = $geocode["lng"];
$query = <<<END
	INSERT INTO `hestia`.`pickups`
	(`idpickup`, `first_name`, `last_name`, `area_code`,
	`phone_num`, `phone_num2`, `street_address`, `second_line`,
	`city`, `zipcode`, `email`, `times`, `tree_info`,
	`equipment`, `add_info`, `reserved`, `lat`, `lng`)
	VALUES (
		'$id',
		'$first_name',
		'$last_name',
		'$area_code',
		'$phone_num',
		'$phone_num2',
		'$street_address',
		'$second_line',
		'$city', '$zipcode',
		'$email', '$times',
		'$tree_info', '$equipment',
		'$add_info', 'open',
		'$lat', '$lng');


END;


echo mysql_query($query, $connection);

?>
<div>
	<ul>
		<li><?php 
		$output = <<<END
		'$id',
		'$first_name',
		'$last_name',
		'$area_code',
		'$phone_num',
		'$phone_num2',
		'$street_address',
		'$second_line',
		'$city', '$zipcode',
		'$email', '$times',
		'$tree_info', '$equipment',
		'$add_info', 'open',
		'$lat', '$lng', $geocodeAddress
END;
		echo $output;
		?></li>
	</ul>
</div>
<?php include("footer.php"); ?>